<template>
  <a-drawer width="35%" :label-col="4" :wrapper-col="14" :visible="open" @close="onClose">
    <a-divider/>

    <a-descriptions title="详细信息" :column="2">
      <a-descriptions-item label="用户名">
        {{ form.memberName }}
      </a-descriptions-item>
      <a-descriptions-item label="活动名称">
        {{ form.activityName }}
      </a-descriptions-item>
      <a-descriptions-item label="计划内容">
        {{ form.planContent }}
      </a-descriptions-item>
    </a-descriptions>
    <!--    <a-form-model ref="form" :model="form" :rules="rules">-->
    <!--      <a-form-model-item label="计划内容" prop="planContent" >-->
    <!--        <div id="planContent" name="planContent" ></div>-->
    <!--      </a-form-model-item>-->
      <!--      <a-form-model-item label="计划内容" prop="memberId" >-->
      <!--        <a-input v-model="form.memberId" placeholder="请输入计划内容" />-->
      <!--      </a-form-model-item>-->
      <!--      <a-form-model-item label="计划内容" prop="activityId" >-->
      <!--        <a-input v-model="form.activityId" placeholder="请输入计划内容" />-->
      <!--      </a-form-model-item>-->
      <!--      <div class="bottom-control">-->
      <!--        <a-space>-->
      <!--          <a-button type="primary" @click="submitForm">-->
      <!--            保存-->
      <!--          </a-button>-->
      <!--          <a-button type="dashed" @click="cancel">-->
      <!--            取消-->
      <!--          </a-button>-->
      <!--        </a-space>-->
      <!--      </div>-->
    </a-form-model>
  </a-drawer>
</template>

<script>
import { getPlan } from '@/api/angel/plan'
import 'vditor/dist/index.css'

export default {
  name: 'CreateForm',
  props: {
  },
  components: {
  },
  data () {
    return {
      loading: false,
      formTitle: '',
      // planContentEditor: '',
      // 表单参数
      form: {
        planId: null,
        planContent: null,
        memberId: null,
        activityId: null
      },
      // 1增加,2修改
      formType: 1,
      open: false,
      rules: {
      }
    }
  },
  filters: {
  },
  created () {
  },
  computed: {
  },
  watch: {
  },
  mounted () {
  },
  methods: {
    // openEditor () {
    //   this.$nextTick(() => {
    //     this.planContentEditor = new Vditor('planContent', {
    //       height: 360,
    //       toolbarConfig: {
    //         pin: true
    //       },
    //       cache: {
    //         enable: false
    //       },
    //       after: () => {
    //         let content = this.form.planContent
    //         if (content === undefined || content === null) {
    //           content = ''
    //         }
    //         // this.planContentEditor.setValue(content)
    //       }
    //     })
    //   })
    // },
    // closeEditor () {
      // this.planContentEditor.destroy()
    // },
    onClose () {
      this.open = false
      // this.closeEditor()
    },
    // 取消按钮
    cancel () {
      this.open = false
      this.reset()
      // this.closeEditor()
    },
    // 表单重置
    reset () {
      this.formType = 1
      this.form = {
        planId: null,
        planContent: null,
        memberId: null,
        activityId: null
      }
    },
    /** 新增按钮操作 */
    handleAdd (row) {
      this.reset()
      this.formType = 1
      this.open = true
      // this.openEditor()
      this.formTitle = '添加'
    },
    /** 修改按钮操作 */
    handleUpdate (row, ids) {
      this.reset()
      this.formType = 2
      const planId = row ? row.planId : ids
      getPlan(planId).then(response => {
        this.form = response.data
        this.open = true
        this.formTitle = '修改'
        // this.openEditor()
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      // this.form.planContent = this.planContentEditor.getValue()
      // this.$refs.form.validate(valid => {
      //   if (valid) {
      //     if (this.form.planId !== undefined && this.form.planId !== null) {
      //       updatePlan(this.form).then(response => {
      //         this.$message.success(
      //           '修改成功',
      //           3
      //         )
      //         this.open = false
      //         this.closeEditor()
      //         this.$emit('ok')
      //       })
      //     } else {
      //       addPlan(this.form).then(response => {
      //         this.$message.success(
      //           '新增成功',
      //           3
      //         )
      //         this.open = false
      //         this.closeEditor()
      //         this.$emit('ok')
      //       })
      //     }
      //   } else {
      //     return false
      //   }
      // })
    }
  }
}
</script>
